Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

time-ordered-set

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

time-ordered-set

Efficiently maintain a set of nodes ordered by the time they were added to the set

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

time-ordered-set

Efficiently maintain a set of nodes ordered by the time they were added to the set

npm install time-ordered-set

Usage

const TOS = require('time-ordered-set')
const s = new TOS()

// add 3 nodes

s.add({
  hello: 'world'
})

const node = s.add({
  hello: 'welt'
})

s.add({
  hello: 'verden'
})

// re-add the 2nd one

s.add(node)
console.log(s.toArray().map(node => node.hello)) // ['world', 'verden', 'welt']

API

const s = new TOS()

Create a new set

node = s.add(node)

Add a new node to the set. Will add the properties node.next and node.prev to the node. Re-adding the same node will move to the latest node.

node = s.remove(node)

Remove a node. Will set node.next and node.prev to null.

bool = s.has(node)

Check if a node has been added.

const array = s.toArray([options])

Get an ordered array out of all the nodes, ordered from oldest to newest. Use options.reverse: true to get from newest to oldest. Set options.limit: number if you only want to get a subset.

s.oldest

Property containing the oldest node.

s.latest

Property containing the newest node.

s.length

Property containing how many nodes are in the set.

License

MIT

FAQs

Package last updated on 08 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc